﻿using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using Algorithms.Common.Data;
using Dqaqs.Common;
using Algorithms.Common;

namespace ProfileTableDqEstimator
{
    public class ProfileTableDqEstimatorImpl: IDataAlgorithmImplementer
    {
        
        public string[][,] Main(params string[] args)
        {
            var tpl = Arguments.ParseSs(args, "Query, InputFilePath");
            var query = tpl.Item1;
            var filePath = tpl.Item2;
            var dataLines = File.ReadAllLines(filePath);

            var profTblQuery = ProfTableQueryHelper.Parse(query);
            var data = CsvHelper.BasicCsvToArray(dataLines).ToArray();

            var runningTime = Stopwatch.StartNew();
            IProfileTableDqEstimatorAlgExecuter algExecuter = new ProfileTableDqEstimatorAlgExecuter();
            var rv = algExecuter.ExecuteAlgorithm(profTblQuery, data.First(), data.Skip(1));
            runningTime.Stop();
            return new[]
			       	{
			       		new[,]
			       			{
			       				{"Running time", runningTime.ElapsedMilliseconds.ToString(CultureInfo.InvariantCulture)},
                                {"Result", rv}
			       			},
                       new[,]{ {"No Data"} }
			       	};
        }
    }
}
